import { createStore } from "vuex";

export default createStore({
  state: {
    rommendList: [],
  },
  getters: {},
  mutations: {
    getData(state, payload) {
      state.rommendList = [...state.rommendList, ...payload.list];
    },
  },
  actions: {
    getDataAsync({ commit }, page) {
      return fetch("http://www.pudge.wang:4000/home/recommend", {
        method: "post",
        headers: {
          "content-type": "application/json",
        },
        body: JSON.stringify({
          count: 3,
          page: page,
        }),
      })
        .then((response) => response.json())
        .then((res) => {
          commit("getData", res.result);
          return res.result.list.length < 3;
        });
    },
  },
  modules: {},
});
